/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_kernel.htm
 *
 * Zhiqim Kernel is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.kernel.model;

import java.io.File;
import java.util.Comparator;

/**
 * 比较器
 *
 * @version v7.0.0 @author zouzhigang 2021年6月23日 新建与整理
 */
public class Comparators
{
    /** 文件顺序比较器，目录在前，文件在后 */
    public static class FileDir implements Comparator<File>
    {
        public int compare(File o1, File o2)
        {
            if (o1.isDirectory() && !o2.isDirectory())
                return -1;//目录在前
            
            if (!o1.isDirectory() && o2.isDirectory())
                return 1;//文件在后
            
            return o1.getName().compareTo(o2.getName());
        }
    }
    
    /** 整型从小到大 */
    public static class IntAsc implements Comparator<Integer>
    {
        @Override
        public int compare(Integer o1, Integer o2)
        {
            return o1 - o2;
        }
    }
    
    /** 整型从大到小 */
    public static class IntDesc implements Comparator<Integer>
    {
        @Override
        public int compare(Integer o1, Integer o2)
        {
            return o2 - o1;
        }
    }
    
    /** 长整型从小到大 */
    public static class LongAsc implements Comparator<Long>
    {
        @Override
        public int compare(Long o1, Long o2)
        {
            return o1 < o2 ? -1 : o1 == o2 ? 0 : 1;
        }
    }
    
    /** 长整型从大到小 */
    public static class LongDesc implements Comparator<Long>
    {
        @Override
        public int compare(Long o1, Long o2)
        {
            return o1 < o2 ? 1 : o1 == o2 ? 0 : -1;
        }
    }
    
    /** 字符串默认顺序比较器 */
    public static class StringAsc implements Comparator<String>
    {
        @Override
        public int compare(String o1, String o2)
        {
            return o1.compareTo(o2);
        }
    }
}
